package com.hopu.petshop.interceptor;

import com.hopu.petshop.entity.PetType;
import com.hopu.petshop.service.PetTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 查询宠物类型的拦截器
 */
public class PetTypeInterceptor implements HandlerInterceptor {

    @Autowired
    private PetTypeService petTypeService;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        List<PetType> petTypes = petTypeService.findAllPetTypes();
        request.setAttribute("petTypes",petTypes);
        return true;
    }
}
